﻿<cfcomponent>

<cfscript>
DB = 'chinalaohu';
</cfscript>
<cfparam name="UUID" default="0" type="string" >

<!---竞拍额度调整--->
<cffunction name="changecredit" access="remote" returnFormat="json">
  <cfscript>
	j = {"success":"0"};
	</cfscript>
	<!---根据UUID查找ID--->
  <cfinvoke component="app.cfc.user" method="uuidgetuid" returnvariable="uuidgetuid" UUID="#uuid#">
  <cfif uuidgetuid.recordcount neq 1>
    <cfset j = {"success":"0","msg":"用户ID错误"}>
  <cfelse>
  	<cfif not isdefined('adjust')>
    	<cfset j = {"success":"0","msg":"缺少参数"}>
    <cfelseif not isnumeric(adjust)>
    	<cfset j = {"success":"0","msg":"请正确填写金额"}>
      
    <cfelse>
      
      <cfscript>
      j = {"success":"1","adjust":adjust};
      </cfscript>
<!---认证额度--->
<cfinvoke component="app.cfc.credit" method="userCreditAuth" returnvariable="userCreditAuth" uid="#uuidgetuid.uid#" />
<!---竞拍额度--->
<cfinvoke component="app.cfc.credit" method="userCredit" returnvariable="userCredit" CreditLimit="#userCreditAuth#" uid="#uuidgetuid.uid#" />
<!---可用额度--->
<cfinvoke component="app.cfc.credit" method="userCreditLimit" returnvariable="userCreditLimit" CreditLimit="#userCredit#" uid="#uuidgetuid.uid#" />
      <cfif userCreditLimit eq adjust>
      	<cfset j = {"success":"0","msg":"竞拍额度未更改"}>
      <cfelse>
				<!---余额--->
        <cfinvoke component="app.cfc.recharge" method="userrecharge" returnvariable="userrecharge" uid="#uuidgetuid.uid#" />
        <cfscript>
        if (userrecharge.recordcount eq 0)
					recharge = 0;
        else 
					recharge = userrecharge.recharge;
        </cfscript>
        <!---保证金--->
        <cfinvoke component="app.cfc.deposit" method="getbzjvalue" returnvariable="userdeposit" uid="#uuidgetuid.uid#" />
        <cfscript>
        if (userdeposit eq 0)
					deposit = 0;
        else 
					deposit = userdeposit;
        </cfscript>
      
        <cfscript>
        //使用掉的余额
        ulost = userCredit - userCreditLimit;
        minc = userCreditAuth - ulost;
        maxc = userCreditLimit + recharge * 50;
        if (adjust lt minc or adjust gt maxc){
					j = {"success":"0","msg":"请在指定范围内进行调整"};
					j = createObject("component",'cfjson').encode(j);
					return j;
        }
        if (adjust gt userCreditLimit){
          financeType = 1;
        }
        else {
          financeType = 0;
        }
        //需要使用余额的部分
        //额度部分
        //urc = adjust + ulost - userCreditAuth;
        //更改部分=新额度-认识额度
        urc = adjust - userCreditLimit;
        //需要扣掉余额部分
        uda = urc / 50;
        ura = -uda;
        //新的余额值
        newrecharge = recharge + ura;
        //ur =  adjust - userCreditLimit;
        //保证金更改值
        //uamount = newdeposit - deposit;
        newdeposit = deposit + uda;
        
        </cfscript>
        <!---余额转保证金--->
        <cfswitch expression="#financeType#">
          <cfcase value="1">
            <cfquery datasource="#DB#" result="rs1">
            insert into user_recharge(uid,financeType,amount,recharge,dt,ip)
            value(#uuidgetuid.uid#,'余额转出',#ura#,#newrecharge#,#now()#,'#cgi.REMOTE_ADDR#')
            </cfquery>
            <cfquery datasource="#DB#">
            insert into user_deposit(uid,rid,financeType,amount,deposit,dt,ip)
            value(#uuidgetuid.uid#,#rs1.GENERATEDKEY#,'余额转入',#uda#,#newdeposit#,#now()#,'#cgi.REMOTE_ADDR#')
            </cfquery>
          </cfcase>
          <cfcase value="0">
            <cfquery datasource="#DB#" result="rs0">
            insert into user_recharge(uid,financeType,amount,recharge,dt,ip)
            value(#uuidgetuid.uid#,'保证金转入',#ura#,#newrecharge#,#now()#,'#cgi.REMOTE_ADDR#')
            </cfquery>
            <cfquery datasource="#DB#">
            insert into user_deposit(uid,rid,financeType,amount,deposit,dt,ip)
            value(#uuidgetuid.uid#,#rs0.GENERATEDKEY#,'保证金转出',#uda#,#newdeposit#,#now()#,'#cgi.REMOTE_ADDR#')
            </cfquery>
          </cfcase>
        </cfswitch>
				<cfset j = {"success":"1","adjust":adjust,"newrecharge":newrecharge,"newdeposit":newdeposit}>
      
      
      </cfif>
    </cfif>
  </cfif>
  <cfscript>
	j = createObject("component",'cfjson').encode(j);
  return j;
	</cfscript>





</cffunction>




<!---SKIP--->

<!---竞拍额度页接口--->
<cffunction name="creditpage" access="remote" returnFormat="json">
  <cfscript>
	j = {"success":"0"};
	</cfscript>
  
	<!---根据UUID查找ID--->
  <cfinvoke component="app.cfc.user" method="uuidgetuid" returnvariable="uuidgetuid" UUID="#uuid#">
  <cfif uuidgetuid.recordcount neq 1>
    <cfset j = {"success":"0","msg":"用户ID错误"}>
  <cfelse>
		<!---余额--->
    <cfinvoke component="app.cfc.recharge" method="getuserrecharge" returnvariable="getuserrecharge" uid="#uuidgetuid.uid#" />
    
    
<!---保证金--->
<cfinvoke component="app.cfc.deposit" method="getbzjvalue" returnvariable="userdeposit" uid="#uuidgetuid.uid#" />
<cfscript>
if (userdeposit eq 0)
deposit = 0;
else 
deposit = userdeposit;
</cfscript>
<!---认证额度--->
<cfinvoke component="app.cfc.credit" method="userCreditAuth" returnvariable="userCreditAuth" uid="#uuidgetuid.uid#" />
<!---竞拍额度--->
<cfinvoke component="app.cfc.credit" method="userCredit" returnvariable="userCredit" CreditLimit="#userCreditAuth#" uid="#uuidgetuid.uid#" />
<!---可用额度--->
<cfinvoke component="app.cfc.credit" method="userCreditLimit" returnvariable="userCreditLimit" CreditLimit="#userCredit#" uid="#uuidgetuid.uid#" />

<cfscript>
//可用保证金
kybzj = deposit;
//认证额度 - 可用额度
othered = userCreditAuth - userCreditLimit;
if (othered gt 0){
	kybzj = kybzj - othered / 50;
}

occupy = userCredit - userCreditLimit;

j = {
"success":"1",
"auctionLimit":{
	"auctionMoney":userCreditAuth,
	"usable":userCredit,
	"occupy":occupy,
	"margin":kybzj,
	"balance":getuserrecharge,
	"rate":50
}
};
</cfscript>
  </cfif>
  
  
  <cfscript>
	j = createObject("component",'cfjson').encode(j);
  return j;
	</cfscript>

</cffunction>

  
  
</cfcomponent>

